/*
 * Goto.cpp
 *
 *  Created on: 17.04.2012
 *      Author: Eugene Kornykhin
 */

#include "Goto.h"
#include "Link.h"
#include <stdexcept>
#include <typeinfo>

Goto::Goto()
: destination(0){

}

Goto::~Goto() {

}

void Goto::execute(Interpreter& interpreter) {
	const PElement &p = interpreter.popPolizElement();
	try {
		const Link &where = dynamic_cast<const Link &>(p);
		destination = where.getDestination();
	} catch(std::bad_cast&) {
		throw std::logic_error("Goto expects a link");
	}
}

PolizPosition Goto::next_position_after(PolizPosition p) const
{
	return destination;
}

bool Goto::isHalt() const {
	return false;
}

Goto* Goto::clone(const Poliz &) const {
	return new Goto();
}

string Goto::toString() const {
	return "[!]";
}
